﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Data;

namespace UniMana.Data
{
    public class Training_TrainingProgram_ScheduleInfo
    {
        #region /*Không thay đổi*/
            public bds m_bds = new bds();

            public void Save()
            {
                m_bds.EndEdit();
                m_data.m_DCSave.SubmitChanges();
            }

            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            #region [Properties - Thuộc tính]
            public Training_TrainingProgram_Schedule Properties
            {
                get { return m_bds.Current as Training_TrainingProgram_Schedule; }
            }
            #endregion

            public Training_TrainingProgram_ScheduleInfo(int subjectKey = 0, int programKey = 0)
            {
                var Iquery = m_data.m_DCSave.Training_TrainingProgram_Schedules.Where(p => p.Training_SubjectKey == subjectKey &&
                                                p.Training_TrainingProgramKey == programKey);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Training_TrainingProgram_Schedule programSchedule = new Training_TrainingProgram_Schedule();
                    programSchedule.Training_SubjectKey = subjectKey;
                    Row = programSchedule;
                    m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }

            public Training_TrainingProgram_ScheduleInfo(int nProgramKey, int nTermKey, int nSubjectKey)
            {
                var Iquery = m_data.m_DCSave.Training_TrainingProgram_Schedules.Where(p => p.Training_TrainingProgramKey == nProgramKey
                                                                                      && p.Training_SubjectKey == nSubjectKey && p.Catalogue_TermKey == nTermKey);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Training_TrainingProgram_Schedule schedule = new Training_TrainingProgram_Schedule();
                    schedule.Training_TrainingProgramKey = nProgramKey;
                    schedule.Training_SubjectKey = nSubjectKey;
                    schedule.Catalogue_TermKey = nTermKey;
                    Row = schedule;
                    m_bds.Add(Row);
                    m_bds.MoveLast();
                }
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
    }
}
